package rsj.api.loginAuth;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.ThinkException;
import common.util.BoxUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.utils.AesRsjUtil;
import rsj.utils.RedisUtils;

@RestController
public class Logout extends BaseLink {

    @RequestMapping(value = "rsj_pub_sso_logout")
    public Box executeLink(Box in) throws ThinkException {
        MapNode data = in.getMapNode("$sso");

        String accessToken = data.getValueDef("Access_Token", null);
        String userIdAndToken = AesRsjUtil.decrypt(accessToken);
        if(!StringUtils.isBlank(userIdAndToken)){
            String userId = userIdAndToken.split(":")[0];
//            JedisUtil.del(userId, BoxUtil.getTid(in));
            RedisUtils.del(userId);
        }

        return BoxUtil.successBox(in, "登出成功！");
    }
}
